<?php
namespace common\services;

use common\models\UserCreditLog;
use yii\data\Pagination;
use yii\data\ActiveDataProvider;

class UserCreditLogServices extends UserCreditLog
{

    /**
     * 用户余额积分查询
     * @param $params
     * @return array
     */
    public function search($params){
        $model = UserCreditLog::find(false);
        $model->orderBy('id desc');

        if (!empty($params['user_id'])) {
            $model->andFilterWhere(['=', 'user_id', $params['user_id']]);
        }

        $dataProvider = new ActiveDataProvider([
            'query' => $model,
            'pagination' => [
                'pagesize' => $params['defaultPageSize'],
            ]
        ]);

        if (isset($params['oper_type']) && $params['oper_type'] != '') {
            $model->andFilterWhere(['=', 'oper_type', $params['oper_type']]);
        }

        if (isset($params['type']) && $params['type'] != '') {
            $model->andFilterWhere(['=', 'type', $params['type']]);
        }

        if (isset($params['status']) && $params['status'] != '') {
            $model->andFilterWhere(['=', 'status', $params['status']]);
        }

        if (!empty($params['keywords'])){
            $model->andFilterWhere(['like', 'user_id', $params['keywords']]);
        }

        return $dataProvider;
    }

}
